package com.luming.ethtran.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.luming.ethtran.domain.DTO.CostCountDto;
import com.luming.ethtran.domain.EthData;
import com.luming.ethtran.domain.DTO.ReceiverCountDto;
import com.luming.ethtran.domain.DTO.SenderCountDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author Luming
 * @Date 2024/9/2 15:15
 * @Description:
 */
public interface EthDataMapper extends BaseMapper<EthData> {
    
    @Select({"SELECT sender, COUNT(*) AS record_count " +
                    "FROM tb_eth_data " +
                    "WHERE sender IN (#{s1}, #{s2}, #{s3}, #{s4}) " +
                    "GROUP BY sender"})
    List<SenderCountDto> countBySenders(@Param("s1") String s1,
                                        @Param("s2") String s2,
                                        @Param("s3") String s3,
                                        @Param("s4") String s4);
    
    
    @Select({"SELECT receiver, COUNT(*) AS record_count " +
            "FROM tb_eth_data " +
            "WHERE receiver IN (#{r1}, #{r2}, #{r3}, #{r4}) " +
            "GROUP BY receiver"})
    List<ReceiverCountDto> countByReceiver(@Param("r1") String r1,
                                           @Param("r2") String r2,
                                           @Param("r3") String r3,
                                           @Param("r4") String r4);
    
    @Select("SELECT cost, COUNT(*) AS count " +
            "FROM tb_eth_data " +
            "WHERE cost BETWEEN 1 AND 10 " +
            "GROUP BY cost " +
            "ORDER BY CAST(cost AS UNSIGNED)")
    List<CostCountDto> getCostDistribution();
}
